from selenium import webdriver
import time
from selenium.webdriver.common.by import By
brower = webdriver.Chrome()
url = 'https://weibo.com/newlogin?tabtype=search&url='
brower.get(url)
time.sleep(15)
list1= []
list2= []
list3= []
j = 0
for k in range(100):
    for i in range(10):
        time.sleep(3)
        res = brower.find_elements_by_class_name("HotTopic_tit_eS4fv")
        for i in res:
            a = i.text
            list1.append(a)
        # print(list1)
        # for i in list1:
        #     print(list1[i])
        # print("-------------------------")

        brower.execute_script("window.scrollBy(0,900)")
    for i in range(len(list1)):
        if list1[i] != "":
            list2.append(list1[i])
    for i in range(len(list2)):
        for k in range(len(list2)):
            if list2[i] == list2[k]:
                j +=1
                if j > 1:
                    list2[k] = ""
        j = 0
    for i in range(len(list2)):
        if list2[i] != "":
            list3.append(list2[i])

    print(list3)
    print(len(list3))

    a = str(input("按任意键刷新,输入x退出"))
    list1= []
    list2= []
    list3= []
    j = 0
    if a == "x":
        brower.quit()
        quit()